﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TruyenCuoi.ViewModel;
using TruyenCuoi.Entity;
using System.Windows.Media;

namespace TruyenCuoi
{
    public partial class ListStoryPage : PhoneApplicationPage
    {
        ListStoryViewModel viewModel;
        public ListStoryPage()
        {
            InitializeComponent();
            viewModel = new ListStoryViewModel();
            DataContext = viewModel;
            var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"];
            var imageBrush = new ImageBrush();
            var imageUri = new Uri(isLightTheme == Visibility.Visible ? "/Assets/480x800.jpg" : "/Assets/BackGroundPage.png", UriKind.Relative);
            imageBrush.ImageSource = new System.Windows.Media.Imaging.BitmapImage(imageUri);
            LayoutRoot.Background = imageBrush;
        }

        private void ItemSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var send = (sender as ListBox);
            var lbx = send.SelectedItem as ReturnStory;
            if (lbx == null) return;
            DetailStoryViewModel.Detail = lbx;
            send.SelectedIndex = -1;
            NavigationService.Navigate(new Uri("/DetailStory.xaml", UriKind.Relative));
        }

        
    }
}